﻿<%@ Page Language="C#" MasterPageFile="../Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>
<%@ Import Namespace="Microsoft.Web.Mvc"%>
<asp:Content ID="indexHead" ContentPlaceHolderID="head" runat="server">
    <title>Admin</title>
</asp:Content>

<asp:Content ID="css_js" ContentPlaceHolderID="js_css" runat="server">
</asp:Content>

<asp:Content ID="head_content" ContentPlaceHolderID="head_content" runat="server">
    <% Html.RenderAction("index","head"); %>
</asp:Content>

<asp:Content ID="indexContentRight" ContentPlaceHolderID="main_content" runat="server">
   <div class="breadcrumb">
    <a href="/admin/home">Trang Chủ Admin</a>:: Quản Lý Sách
</div>
<%if(ViewData["success"].ToString()!="") {%>
  <div class="success"><%=ViewData["success"] %></div>
<%} else {%>
  <div class="success" style="display:none;"></div>
<%} %>

<%if(ViewData["warning"].ToString()!="") {%>
  <div class="warning"><%=ViewData["warning"]%></div>
<%} else {%>
  <div class="warning" style="display:none;"></div>
<%} %>

<div class="box">
  <div class="left"></div>
  <div class="right"></div>
  <div class="heading">
    <h1 style="background-image: url('/admin/content/images/product.png');">Sách</h1>
    <div class="buttons"><a onclick="location = '/admin/book/detail'" class="button"><span>Thêm</span></a><a onclick="if(window.confirm('Bạn có chắc muốn xóa sách này ?')) $('form').submit();" class="button"><span>Xoá</span></a></div>
  </div>
  <div class="content">
 	<div id="insert_cate" style="height:35px;">
		<span style="font-weight: bold;" >Mã sách : </span>
		<input id="book_code" type="textbox" value="<%=ViewData["keyword"] %>" maxlength="10" size="50" />
		&nbsp;&nbsp;
		<a onclick="search_code()" class="button"><span>Tìm</span></a>
		<a onclick="show_all()" class="button" <%if(ViewData["keyword"].ToString()=="") {%>style="display:none;"<%} %>><span>Hủy Tìm</span></a>
	</div> 
    <form action="/admin/book/deleteBooks" method="post" enctype="multipart/form-data" id="form">
      <table class="list">
        <thead>
          <tr>
            <td style="text-align: center;" width="1"><input onclick="$('input[name*=\'selected\']').attr('checked', this.checked);" type="checkbox" /></td>
            <td class="center">Image</td>
            <td class="left">              
				<a href="/admin/book?sort=bc&<%if(ViewData["sort"].ToString()=="bc") {%>type=<%=ViewData["type"] %>&<%} %>keyword=<%=ViewData["keyword"] %>" <%if(ViewData["sort"].ToString()=="bc") {%>class="<%=ViewData["typeCur"] %>"<%} %>>Mã sách</a>
            </td>			
            <td class="left">              
				<a href="/admin/book?sort=bn&<%if(ViewData["sort"].ToString()=="bn") {%>type=<%=ViewData["type"] %>&<%} %>keyword=<%=ViewData["keyword"] %>" <%if(ViewData["sort"].ToString()=="bn") {%>class="<%=ViewData["typeCur"] %>"<%} %>>Tên sách</a>
            </td>
            <td class="left">              
				<a href="/admin/book?sort=cn&<%if(ViewData["sort"].ToString()=="cn") {%>type=<%=ViewData["type"] %>&<%} %>keyword=<%=ViewData["keyword"] %>" <%if(ViewData["sort"].ToString()=="cn") {%>class="<%=ViewData["typeCur"] %>"<%} %>>Thể loại</a>
            </td>
            <td class="left">              
				<a href="/admin/book?sort=pb&<%if(ViewData["sort"].ToString()=="pb") {%>type=<%=ViewData["type"] %>&<%} %>keyword=<%=ViewData["keyword"] %>" <%if(ViewData["sort"].ToString()=="pb") {%>class="<%=ViewData["typeCur"] %>"<%} %>>Giá bán</a>
            </td>			
            <td class="right">              
				<a href="/admin/book?sort=qb&<%if(ViewData["sort"].ToString()=="qb") {%>type=<%=ViewData["type"] %>&<%} %>keyword=<%=ViewData["keyword"] %>" <%if(ViewData["sort"].ToString()=="qb") {%>class="<%=ViewData["typeCur"] %>"<%} %>>Số lượng bán</a>
            </td>
            <td class="left">              
				<a href="/admin/book?sort=pr&<%if(ViewData["sort"].ToString()=="pr") {%>type=<%=ViewData["type"] %>&<%} %>keyword=<%=ViewData["keyword"] %>" <%if(ViewData["sort"].ToString()=="pr") {%>class="<%=ViewData["typeCur"] %>"<%} %>>Giá thuê</a>
            </td>			
            <td class="right">              
				<a href="/admin/book?sort=qr&<%if(ViewData["sort"].ToString()=="qr") {%>type=<%=ViewData["type"] %>&<%} %>keyword=<%=ViewData["keyword"] %>" <%if(ViewData["sort"].ToString()=="qr") {%>class="<%=ViewData["typeCur"] %>"<%} %>>Số lượng thuê</a>
            </td>			
            <td class="left">              
				<a href="/admin/book?sort=st&<%if(ViewData["sort"].ToString()=="st") {%>type=<%=ViewData["type"] %>&<%} %>keyword=<%=ViewData["keyword"] %>" <%if(ViewData["sort"].ToString()=="st") {%>class="<%=ViewData["typeCur"] %>"<%} %>>Trạng thái</a>
            </td>
            <td class="right"></td>
          </tr>
        </thead>
        <tbody id="list_book">
            <%=ViewData["listBook"] %>
         </tbody>
      </table>
    </form>
  </div>
</div>
</div>
<script type="text/javascript">
    function search_code() {
        if ($.trim($("#book_code").val()) != "")
            document.location.href = "/admin/book?sort=<%=ViewData["sort"] %>&type=<%=ViewData["typeCur"] %>&keyword=" + $.trim($("#book_code").val());
    } 
    
    function show_all() {
        document.location.href = "/admin/book?sort=<%=ViewData["sort"] %>&type=<%=ViewData["typeCur"] %>";
        $("#book_code").val("");
    } 
    
    function deleteBook(id) {
        if(window.confirm("Bạn có chắc muốn xóa sách này ?"))
        {
                if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
                    xmlhttp = new XMLHttpRequest();
                }
                else {// code for IE6, IE5
                    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
                }

                xmlhttp.onreadystatechange = function() {
                    if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                        if (xmlhttp.responseText == -3)
                            document.location.href = "/admin/login";
                        else if (xmlhttp.responseText == -1) {
                            $(".warning").html("Cố lỗi đường truyền ! Vui lòng thử lại !");
                            $(".warning").show();
                            $(".success").hide();
                        } 
                        else if (xmlhttp.responseText == -5) {
                            $(".warning").html("Hãy xóa hết hóa đơn cho thuê trước khi xóa sách này !");
                            $(".warning").show();
                            $(".success").hide();
                        }
                        else if (xmlhttp.responseText == -6) {
                            $(".warning").html("Hãy xóa hết hóa đơn trước khi xóa sách này !");
                            $(".warning").show();
                            $(".success").hide();
                        }
                        else {
                            $(".success").html("Xóa sách thành công !");
                            $(".success").show();
                            $(".warning").hide();
                            $("#list_book").html(xmlhttp.responseText);
                        }
                    }
                }
                xmlhttp.open("GET", "/admin/book/jsonDeleteBook?page=<%=ViewData["page"] %>&sort=<%=ViewData["sort"] %>&type=<%=ViewData["typeCur"] %>&keyword=" + $.trim($("#book_code").val())+"&id=" + id, true);
                xmlhttp.send();
            }
      }
</script>
</asp:Content>
